﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using BEGDC.CC.Web.UserControls;
using BEGDC.CC.Entity;
using BEGDC.CC.BL.Workflow;
using BEGDC.CC.BL.Common;
using BEGDC.Utility.Castle;

namespace BEGDC.CC.Web.SystemManagement
{
	/// <summary>
	/// Summary description for CurrencyExchange.
	/// </summary>
	public class CurrencyExchange : System.Web.UI.Page
	{
		#region VARIABLES

		protected System.Web.UI.WebControls.TextBox Ctl_CNY;
		protected System.Web.UI.WebControls.Button Btn_Save;
		#endregion

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!this.IsPostBack)
			{
				InitForm();
			}
		}

		#region InitForm
		private void InitForm()
		{
			IUtility UtilityService = AppContainer.Instance[ServiceConst.UtilityService] as IUtility;
			BEGDC.CC.Entity.ExchangeRate exchange = UtilityService.GetCurrencyExchange();
			this.Ctl_CNY.Text = exchange.Exchange.ToString();
		}
		#endregion

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Btn_Save.Click += new System.EventHandler(this.Btn_Save_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		#region
		private void Btn_Save_Click(object sender, System.EventArgs e)
		{
			IUtility UtilityService = AppContainer.Instance[ServiceConst.UtilityService] as IUtility;
			BEGDC.CC.Entity.ExchangeRate exchange = UtilityService.GetCurrencyExchange();
            try
            {
                exchange.Exchange = Convert.ToDouble(this.Ctl_CNY.Text);
                UtilityService.SaveCurrencyExchange(exchange);
            }
            catch
            {
                Page.RegisterClientScriptBlock("", "<script>alert('Error exchange format!Please input numeric')</script>");
            }
			
		}
		#endregion
	}
}
